package the.guanzhong.express.interfaces.controller;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wisteria.framework.web.APIResult;
import the.guanzhong.express.interfaces.controller.req.BooksAddReq;
import the.guanzhong.express.interfaces.controller.req.BooksListReq;
import the.guanzhong.express.interfaces.controller.req.BooksModifyReq;
import the.guanzhong.express.interfaces.controller.req.BooksRemoveReq;
import the.guanzhong.express.interfaces.controller.resp.BooksListResp;
import the.guanzhong.express.service.ExpressBooksService;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 地址薄控制器
 */
@Api(tags = "Express")
@RestController
@RequestMapping("/express/books")
public class ExpressBooksController {

    @Resource
    private ExpressBooksService expressBooksService;

    /**
     * 新增地址簿
     * @param req   新增的数据
     * @return
     */
    @PostMapping("/add")
    public APIResult<Boolean> add(@RequestBody @Valid BooksAddReq req) {
        return APIResult.success(expressBooksService.add(req));
    }

    /**
     * 删除地址薄
     * @param req 地址薄信息
     * @return
     */
    @PostMapping("/remove")
    public APIResult<Boolean> remove(@RequestBody @Valid BooksRemoveReq req) {
        return APIResult.success(expressBooksService.remove(req));
    }

    /**
     * 修改地址薄
     * @param req   地址薄信息
     * @return
     */
    @PostMapping("/modify")
    public APIResult<Boolean> modify(@RequestBody @Valid BooksModifyReq req) {
        return APIResult.success(expressBooksService.modify(req));
    }

    /**
     * 查询地址薄列表
     * @param req   查询条件
     * @return
     */
    @PostMapping("/list")
    public APIResult<List<BooksListResp>> add(@RequestBody @Valid BooksListReq req) {
        return APIResult.success(expressBooksService.list(req));
    }

}
